﻿using System.Web.Mvc;
using System.Web.UI.WebControls;
using NInject.Practice;

namespace Ninject.Web.Controllers
{
    public class TestController:Controller
    {
        private readonly IMessageSender _messageSender;
        private readonly IMessageProvider _messageProvider;
        private readonly IKernel _kernel;

        public TestController(IMessageSender messageSender,IMessageProvider messageProvider,IKernel kernel)
        {
            _messageSender = messageSender;
            _messageProvider = messageProvider;
            _kernel = kernel;
        }

        public ActionResult Message()
        {
            return  Content(_messageProvider.Message());
        }

        public ActionResult Message2()
        {
            var messageProvider = DependencyResolver.Current.GetService<IMessageProvider>();

            return Content(messageProvider.Message());
        }

        public ActionResult ResolveHandler()
        {
            var handlers = _kernel.GetAll<IHandler<string>>();
            string str = "";
            foreach (var handler in handlers)
            {
                str += handler.Handle("start");
            }

            return Content(str);
        }
    }
}